<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>history</title>
    <script>
        ROOT_URL = '{:request()->root()}';
    </script>
    <script type="text/javascript" src="__libs__/jquery/jquery.min.js?v=__lkversion__"></script>
    <script src="__libs__/layer/layer.js?v=__lkversion__" type="text/javascript"></script>
    <script src="__libs__/layui/layui.js?v=__lkversion__" type="text/javascript"></script>
    <script src="__libs__/jquery/jquery.cookie.js?v=__lkversion__" type="text/javascript"></script>

    <link href="__libs__/layui/css/layui.css?v=__lkversion__" rel="stylesheet">
    <link href="__style__/admin/index.css?v=__lkversion__" type="text/css" rel="stylesheet" />
    <link href="__style__/admin/index_me.css?v=__lkversion__" type="text/css" rel="stylesheet" />

    <link href="__style__/admin/new.css?v=1" type="text/css" rel="stylesheet"/>
    <link href="__style__/admin/ymwl_common.css?v=1" type="text/css" rel="stylesheet"/>
    <style>
        body{
            background: #ffffff;
        }
        .outer-left {
            float: left;
            width: 500px;
            position: relative;
            left: 60px;
            top: 20px;
            clear: both;
            font-size: 14px;
        }


        .outer-right {
            float: right;
            width: 500px;
            position: relative;
            right: 60px;
            clear: both;
            font-size: 14px;
        }
        .no_chats-pic {
            display: inline-block;
            width: 138px;
            height: 67px;
            background: url('__image__/admin/bgspirt.png') no-repeat;
            background-position: -286px;
            position: absolute;
            top: 300px;
            left: 250px;
        }

        .no_history_icon {
            display: inline-block;
            width: 90px;
            height: 67px;
            background: url('__image__/admin/bgspirt.png') no-repeat;
            background-position: -90px;
            position: absolute;
            top: 300px;
            left: 44%;
        }
        .cc, :after, :before {
            -webkit-box-sizing: border-box;
            /* box-sizing:border-box; */
        }

    </style>

<body>
<div id="wrap" class="cc" style="width: 100%;height:700px;overflow-y: auto;background-color: #fff">
    <ul class="conversation" style="padding-top: 20px;">


    </ul>
</div>
</body>

<script src="__script__/functions.js?v={:time()}" type="text/javascript"></script>
<script src="__script__/admin/worker.js?v={:time()}" type="text/javascript"></script>0
<script>

    var login_user_id = "{$user.id}";
    var user;
    var visitor;
    var history_chat_content_id  = 0;
    var now_chat_content_id  = 0;
    var last_showtime   = '';
    var mindata   = '';
    //获取最近历史消息
    function getdata(history_chat) {

        var avatver,cha;
        var sdata = $.cookie("cu_com");
        if (sdata) {
            var jsondata = $.parseJSON(sdata);
            avatver = jsondata.avatar;
            cha =jsondata.visitor_id;
        }
        var showtime;
        var curentdata =new Date();
        var time =curentdata.toLocaleDateString();
        var cmin =curentdata.getMinutes();

        if($.cookie("allhid") != "" ){
            cid =$.cookie("allhid");
        }else{
            cid ='';
        }



        $.ajax({
            url:"{:url('conversation')}",
            type: "get",
            data: {
                chat_id: "{$chat_id}",chat_content_id:cid
            },
            dataType:'json',
            success: function (res) {

                // alert(res);
                if (res.code == 0) {

                    var str = "";
                    var data = res.data.data;
                    if(data.length >0){
                        mindata = data[0].id;
                        $("#top_div").remove();
                    }
                    $.each(data, function (k, v) {
                        if (v.id < mindata) {
                            mindata = v.id;
                        }
                        receiveChatMessage(v, history_chat);
                    });

                        // $(".conversation").prepend(str);

                    console.log(res.data)
                    if (res.data.last_page != res.data.current_page) {
                        // 还有分页
                        more_page = true;
                        $(".conversation").prepend("<div id='top_div' class='showtime'>查看更多</div>");
                        history_chat_content_id = mindata;
                    } else {
                        more_page = false;
                        $(".conversation").prepend("<div id='top_div' class='showtime'>已没有数据</div>");
                        history_chat_content_id = '';
                    }


                    if(res.data.data.length >0){
                        $.cookie("allhid",mindata);

                    }
                }
            }
        });
    }



    document.getElementById("wrap").onscroll = function(){
        var t =  document.getElementById("wrap").scrollTop;
        console.log(t)
        if( t == 0 ) {
            if(mindata != "" && more_page){
                getdata(true);
            }
        }
    }



    function init(){

        $.cookie('allhid','');
       getdata(false);

    }


    window.onload = init();

</script>
</html>
